<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>阿里云视频点播_HyperCMF</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/static/favicon.ico">
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <script src="/static/js/jquery.min.js?v=2.1.4"></script>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <script src="/static/layui/layui.2.7.6.js"></script>
    <script src="/static/js/base.js"></script>

    <style type="text/css">

    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" placeholder="名称搜索" autocomplete="off"
                                   class="layui-input" style="width: 80px">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">上传时间：</label>
                        <div class="layui-input-block">
                            <input type="text" name="created_at" placeholder="请输入区间" autocomplete="off"
                                   class="layui-input" id="test6" style="width:180px">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">上传状态：</label>
                        <div class="layui-input-block"  style="width: 100px">
                            <select name="upload_status" id="category" lay-verify="" style="width: 100px">
                                <option value="">全部</option>
                                <option value="1">上传中</option>
                                <option value="2">上传完成</option>
                                <option value="3">转码中</option>
                                <option value="4">转码成功</option>

                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">状态：</label>
                        <div class="layui-input-block"  style="width: 100px">
                            <select name="status" id="status" lay-verify="" style="width: 100px">
                                <option value="">全部</option>
                                <option value="0">已下架</option>
                                <option value="1">正常</option>

                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
            <table class="layui-hide fileList" id="dataTable" lay-filter="dataTable"></table>
        </div>
    </div>
</div>


<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">上传视频</button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="chosed">使用选中</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除选中</button>
    </div>
</script>

<!--<script type="text/html" id="cityTpl">-->
<!--    <select id="City1" class="layui-border" lay-ignore>-->
<!--        <option value="0">禁用</option>-->
<!--        <option value="1">正常</option>-->
<!--    </select>-->
<!--</script>-->

<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-default layui-btn-xs" lay-event="edit">修改</a>
</script>

<script>
    layui.use(['table', 'dropdown','layer','laydate','form'], function(){
        var table = layui.table;
        var dropdown = layui.dropdown;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var form = layui.form;
        var media_type = getQueryVariable('media_type')
        if(!media_type){
            media_type=''
        }
        // layer.msg('本示例演示的数据为静态模拟数据，<br>实际使用时换成您的真实接口即可。', {
        //     closeBtn: 1,
        //     icon: 6,
        //     time: 21*1000,
        //     offset: '21px'
        // });
        //日期范围
        laydate.render({
            elem: '#test6'
            ,range: '~'
        });
        // 创建渲染实例
        table.render({
            elem: '#dataTable'
            ,url:'/admin/vod/aliyunVod'
            ,headers:{
                'token':localStorage.getItem('hypercmfname')+'_'+localStorage.getItem('token'),
                'accept':'*/*'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar:['filter','exports']
            ,height: 'full-80' // 最大高度减去其他容器已占有的高度差
            ,cellMinWidth: 80
            // ,totalRow: true // 开启合计行
            ,page: true
            ,response: {
                statusCode: 1 //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                console.log(res.data.data)
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            }
            , cols: [[ //表头
                {type: 'checkbox'}
                , {field: 'id', title: 'ID', width: 80, sort: true}
                , {field: 'title', title: '视频名称',minWidth:155}
                ,{field:'cover', width:180, title: '封面图', templet:function(d){
                        return '<div class="layer-photos"><img layer-pid="'+d.id+'" layer-src="'+d.cover+'" alt="'+d.title+'" src="'+d.cover+'"></div>'
                    }}
                , {field: 'status', title: '状态', width: 60,
                    templet: function (d) {
                        if (d.status == 0) {
                            return '已下架';
                        } else if (d.status == 1) {
                            return '正常';
                        }
                    }
                }
                , {field: 'upload_status', title: '上传状态', width: 100,
                    templet: function (d) {
                        if (d.upload_status == 1) {
                            return '上传中';
                        } else if (d.upload_status == 2) {
                            return '上传成功';
                        }else if (d.upload_status == 3) {
                            return '转码中';
                        }else if (d.upload_status == 4) {
                            return '转码成功';
                        }else{
                            return '上传失败'
                        }
                    }
                }
                , {field: 'quality', title: '清晰度',minWidth:155,
                    templet:function (d) {
                        if(d.quality==1){
                            return '标准';
                        }else if(d.quality==2){
                            return '高清';
                        }else if(d.quality==3){
                            return '超清';
                        }else if(d.quality==4){
                            return '2K';
                        }
                    }
                }
                , {field: 'm3u8', title: 'm3u8地址', width: 200}
                , {field: 'desc', title: '视频简介',minWidth:155}
                , {field: 'video_id', title: '视频ID',minWidth:205}
                , {field: 'path', title: '源文件地址', width: 200}
                , {field: 'created_at', title: '创建时间', width: 200,templet:function(d){
                    return timestampToTime(d.created_at)
                    }}
                , {fixed: 'right',title: '操作', minWidth: 200, align: 'center', toolbar: '#bar'}
            ]]
            ,done: function(){
                var id = this.id;

                layer.photos({
                    photos: '.layer-photos'
                    ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });

            }
            ,error: function(res, msg){
                console.log(res, msg)
            }
        });
        // request('/admin/file/getCategory',{}).then((res)=>{
        //     var html = ''
        //     for(let i of res.data){
        //         html+=`<option value="${i.id}">${i.name}</option>`
        //     }
        //     $("#category").append(html)
        //     form.render()
        // })
        // 工具栏事件
        table.on('tool(dataTable)', function(obj){ // 双击 toolDouble
            var data = obj.data;
            // console.log(obj)
            if(obj.event === 'edit') {
                layer.open({
                    title: '修改信息',
                    type: 2,
                    shadeClose: true,
                    area: ['90%', '90%'],
                    content: '/admin/vod/edit.html?a=1&id=' + obj.data.id
                });
            }
        })

        table.on('toolbar(dataTable)', function(obj){
            var id = obj.config.id;
            var checkStatus = table.checkStatus(id);
            var othis = lay(this);
            switch(obj.event){
                case 'add':
                    layer.open({
                        title: '上传视频到阿里云VOD',
                        type: 2,
                        shadeClose:true,
                        area: ['90%','80%'],
                        content: '/admin/vod/upload.html?id=1'
                    });
                    break;
                case 'chosed':
                    var data = checkStatus.data;
                    if(data.length==0){
                        layer.msg('请勾选文件')
                        return false;
                    }
                    // layer.alert(layui.util.escape(JSON.stringify(data)));
                    let from = getQueryVariable('from')
                    if(!from || from==''){
                        parent.GetChildValue(data)
                    }else{
                        parent.GetChildValue(data,from)
                    }

                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

                    parent.layer.close(index); //执行关闭
                    break;
                case 'del':
                    var data = checkStatus.data;
                    // layer.alert(layui.util.escape(JSON.stringify(data)));
                    if(data.length==0){
                        layer.msg('请勾选文件')
                        return false;
                    }
                    var a = Math.ceil(Math.random()*100)
                    layer.prompt({title: '为了防止误操作，请输入：'+ a, formType: 2}, function(text, index){
                        if(text!=a){
                            layer.msg('验证失败');
                            setTimeout(function () {
                                layer.close(index);
                            },1000)
                        }else{
                            request('/admin/vod/delVod',{data:checkStatus.data,status:0}).then((res)=> {
                                if(res.code==1){
                                    layer.msg('操作成功',{
                                        icon: 1,
                                        time: 1000 //1秒关闭（如果不配置，默认是3秒）
                                    },function () {
                                        layer.closeAll()
                                        table.reload('dataTable')
                                    })

                                }else{
                                    layer.alert(res.msg,{icon:5})//1√，2×，3问号，4锁，5不开心，6开心
                                }
                            })
                        }
                    });
                    break;
                case 'LAYTABLE_TIPS':
                    layer.alert('使用说明：<p>点击图片查看大图</p><p>每个模块文件选中后进行相关操作</p><p>双击每块空白处获取详细信息</p>');
                    break;
            };
        });


        //触发表格复选框选择
        table.on('checkbox(dataTable)', function(obj){
            console.log(obj)
        });

        //触发表格单选框选择
        table.on('radio(dataTable)', function(obj){
            console.log(obj)
        });

        // 行单击事件
        table.on('row(dataTable)', function(obj){
            console.log(obj);
            //layer.closeAll('tips');
            // var data = obj.data
            // let from = getQueryVariable('from')
            // if(!from || from==''){
            //     parent.GetChildValue(data)
            // }else{
            //     parent.GetChildValue(data,from)
            // }
            //
            // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //
            // parent.layer.close(index); //执行关闭
        });
        // 行双击事件
        table.on('rowDouble(dataTable)', function(obj){
            console.log(obj);
            var data=obj.data
            layer.alert("<p>文件名："+data.title+"</p><p>文件地址："+data.m3u8+"</p><p>Video_id:"+data.video_id+"</p>")
        });

        // 单元格编辑事件
        table.on('edit(dataTable)', function(obj){
            var field = obj.field //得到字段
                ,value = obj.value //得到修改后的值
                ,data = obj.data; //得到所在行所有键值

            var update = {};
            update[field] = value;
            obj.update(update);
        });
        form.on('submit(search)',function (data) {
            table.reload('dataTable',{
                where:data.field,
                page:{
                    curr:1
                }
            })

        })
    });
    function timestampToTime(timestamp) {
        var date = new Date(timestamp*1000 );//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = date.getDate() + ' ';
        h = date.getHours() + ':';
        m = date.getMinutes() + ':';
        s = date.getSeconds();
        return Y+M+D+h+m+s;
    }
</script>

</body>
</html>